define(['vue'],function(vue){
    return function(data){
        new vue({
            el:'#menu',
            data:{
               menus:data,
                active:{},
                main:-1,
                current:-1,
            },
            watch:{
                active:{
                    handler:function(){
                        var _this = this;
                        var _sum = 4; //字体限制为4个
                        _this.$refs.count.setAttribute("maxlength",_sum);
                    },
                    deep:true
                }
            },
            // updated(){
            //         if (this.active.name.length > this.titleMaxLength) {
            //             this.active.name = String(this.active.name).slice(0, this.titleMaxLength);
            //         }
            // },
            methods:{
                add(){
                    this.current=-1;
                    if(this.menus.length<3){
                        var item = {type:'view',name:'菜单',url:'',sub_button:[]};
                        this.menus.push(item);
                        this.setActive(item);
                        this.main=this.menus.length-1;
                    }
                },
                del(k){
                    this.menus.splice(k,1);
                    this.active={};
                    this.main=-1;
                    this.current=-1;
                },
                setActive(item,k,n){
                    this.active=item;
                    this.main=k;
                    this.current=n;
                    // console.log(main);
                },
                addsub(v,k){
                    this.main=k;
                    if (v.sub_button.length < 5){
                        var item = {type:'view',name:'子菜单',url:''};
                        v.sub_button.push(item);
                        this.setActive(item,k);
                        this.current=v.sub_button.length-1;
                        // console.log(this.index);
                    }
                },
                delsub(v,n){
                    v.sub_button.splice(n,1);
                    this.active={};
                    this.main=-1;
                    this.current=-1;
                }
            }
        })
    }
});